package l1j.server.server.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;

import l1j.server.Config;
import l1j.server.L1DatabaseFactory;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;
import l1j.server.server.utils.SQLUtil;

public class L1DeleteItem {
	public void logDeleteItem(L1PcInstance pc,L1ItemInstance item,int count,String type){
		if (!Config.writeDeleteItemLog)
			return;
		Connection con = null;
		PreparedStatement pstm = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con
					.prepareStatement("INSERT INTO log_deleteitem SET time=?,pcname=?,itemname=?,count=?,type=?,itemobj=?,pcobj=?");
			pstm.setTimestamp(1, new Timestamp(System.currentTimeMillis()));
			pstm.setString(2, pc.getName());
			pstm.setString(3, item.getName() + (item.getLogName()));
			pstm.setInt(4, count);
			pstm.setString(5, type);
			pstm.setInt(6, item.getId());
			pstm.setInt(7, pc.getId());
			pstm.execute();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}
}
